const mongoose = require('mongoose');

const adminsModel = mongoose.model('adminsModel');
const adminsLoginModel = mongoose.model('adminsLoginModel');
const pictureModel = mongoose.model('pictureModel');
//渲染
module.exports.Admin = async function ({ currentPage,pageSize }) {
    const data = await adminsModel
        .find()
        .limit(pageSize - 0)
        .skip((currentPage - 1) * pageSize);
    const total = await adminsModel.countDocuments();
    return { data, total };
}
//新增
module.exports.add = async function ({ name, pirce, shopid, bool, stock,img }) {
    const data = await adminsModel.create({ name, pirce, shopid, bool, stock ,img})
    return { data };

    // console.log(data)
}
//删除
module.exports.del = async function ({ _id }) {
    const data = await adminsModel.deleteOne({ _id })
    return { data };

    console.log(data)
}
//查询
module.exports.query = async function ({ choose, value }) {
    const data = await adminsModel.find({ [choose]: { $regex: value, $options: '$i' } })
    // const data = await adminsModel.find({[choose]: value})
    return { data };

    // console.log(data)
}
//修改
module.exports.revise = async function ({ _id, shopid, name, pirce, bool, stock }) {
    return await adminsModel.updateOne({ _id }, { shopid, name, pirce, bool, stock });
    // const data = await adminsModel.find({[choose]: value})


    // console.log(data)
}
/********************************************************/
//超级管理员 渲染
module.exports.superAdmin = async function ({ currentPage,pageSize }) {
    const data = await adminsLoginModel
        .find()
        .limit(pageSize - 0)
        .skip((currentPage - 1) * pageSize);
    const total = await adminsLoginModel.countDocuments();
    return { data, total };
}
//轮播图渲染  picture
module.exports.picture = async function () {
    const data = await pictureModel
        .find()
       
    const total = await pictureModel.countDocuments();
    return { data, total };
}

//添加轮播图 addpic

module.exports.addpic = async function ({ img }) {
    const data = await pictureModel.create({ img})
    return { data };

    // console.log(data)
}